Add gtk_ui_manager_add_ui_from_resource
authorAlexander Larsson <alexl@redhat.com>
Thu, 12 Jan 2012 18:00:39 +0000 (19:00 +0100)
committerAlexander Larsson <alexl@redhat.com>
Mon, 16 Jan 2012 12:59:58 +0000 (13:59 +0100)
This is a helper function to easily add ui from resource files.

gtk/gtkuimanager.c
gtk/gtkuimanager.h

index 82c638c4e2bbbd36d7809e017af08c5f269b333a..1e644d29ef2bfd20e545aa5e84464dbbe05a7960 100644 (file)
@@ -2001,6 +2001,41 @@ gtk_ui_manager_add_ui_from_file (GtkUIManager *manager,
   return res;
 }
 
+/**
+ * gtk_ui_manager_add_ui_from_resource:
+ * @manager: a #GtkUIManager object
+ * @resource_path: the resource path of the file to parse
+ * @error: return location for an error
+ *
+ * Parses a resource file containing a <link linkend="XML-UI">UI definition</link> and
+ * merges it with the current contents of @manager.
+ *
+ * Return value: The merge id for the merged UI. The merge id can be used
+ *   to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
+ *   the return value is 0.
+ *
+ * Since: 3.4
+ **/
+guint
+gtk_ui_manager_add_ui_from_resource (GtkUIManager *manager,
+                                    const gchar  *resource_path,
+                                    GError      **error)
+{
+  GBytes *data;
+  guint res;
+
+  g_return_val_if_fail (GTK_IS_UI_MANAGER (manager), 0);
+
+  data = g_resources_lookup_data (resource_path, 0, error);
+  if (data == NULL)
+    return 0;
+
+  res = add_ui_from_string (manager, g_bytes_get_data (data, NULL), g_bytes_get_size (data), FALSE, error);
+  g_bytes_unref (data);
+
+  return res;
+}
+
 /**
  * gtk_ui_manager_add_ui:
  * @manager: a #GtkUIManager
index d07ccccbdb5415c336c1a83c56ae70905703006a..8573f2aeca1660550cf0d59209b24515437dcef1 100644 (file)
@@ -152,6 +152,9 @@ guint          gtk_ui_manager_add_ui_from_string  (GtkUIManager          *manage
 guint          gtk_ui_manager_add_ui_from_file    (GtkUIManager          *manager,
                                                   const gchar           *filename,
                                                   GError               **error);
+guint          gtk_ui_manager_add_ui_from_resource(GtkUIManager          *manager,
+                                                  const gchar           *resource_path,
+                                                  GError               **error);
 void           gtk_ui_manager_add_ui              (GtkUIManager          *manager,
                                                   guint                  merge_id,
                                                   const gchar           *path,